package org.kth.dks.util;


public class MathMisc{

    public static boolean belongsTo(long id, long start, long end, long n) { // t E ]beg,end]
	long nx = 0;
	long ny = MathMisc.modMinus(end, start, n);
	long nid = MathMisc.modMinus(id, start, n);
	return start == end || (nid > nx && nid <= ny);
    }

    public static  boolean belongsTonn(long id, long start, long end, long n) { // t E ]beg,end[
	long nx = 0;
	long ny = MathMisc.modMinus(end, start, n);
	long nid = MathMisc.modMinus(id, start, n);
	return (start ==  end && id != start) || (nid > nx && nid < ny);
    }

    public static  boolean belongsToI(long id, long start, long end, long n) { // t E [beg,end[
	long nx = 0;
	long ny = MathMisc.modMinus(end, start, n);
	long nid = MathMisc.modMinus(id, start, n);
	return start == end || (nid >= nx && nid < ny);
    }

    public static  boolean belongsToII(long id, long start, long end, long n) { // t E [beg,end]
	long nx = 0;
	long ny = MathMisc.modMinus(end, start, n);
	long nid = MathMisc.modMinus(id, start, n);
	return ((start == end) && (end == id)) || (nid >= nx && nid <= ny);
    }


    public static long distanceClockWise(long from, long to, long n){
	return modMinus(to, from, n);
    }

    public static long distanceAntiClockWise(long from, long to, long n){
	return modMinus(from, to, n);
    }

    public static long modPlus(long x, long y, long n){
	return (x + y) % n;
    }

    public static long modMinus(long x, long y, long n){
	return (n + x - y ) % n;
    }

    public static long nThroughKPowerL(long n, int k, int l){
	return (long)((long)(double)n / (double)(Math.pow(k,l)));
    }
}
